package tag39_03_09.threadsWeiter;

public class Th20_waitNotify {

	static int count=0;
	static final Object monitor = new Object(); 
	
	public static void main(String[] args)  {

		Thread hersteller = new Thread(){
			@Override
			public void run() {

				while(true){
					System.out.println("Es wird produziet...");
					synchronized (monitor){
						count = 1;
						monitor.notifyAll();	
					}
					System.out.println("Fertig");		
				}
			
			}
			
		};
		hersteller.start();
		
		//-------------------------------------------------------------
		
		Thread abnehmer = new Thread(){
			@Override
			public void run()   {
				while(true){
					synchronized (monitor){
						if(count>0){
							System.out.println("Abnehmen ...");
							count = 0;
						}else{
							System.out.println("Umsonst...");
							try {monitor.wait();}catch (InterruptedException ie){ie.printStackTrace();}
						}
					
					}
						
				} //while
				 
			} // run
		};
		abnehmer.start();
		
	}

}
